/*
 * Copyright (c) 2017. 深圳一七网络科技. All rights reserved.
 */

package com.fenxiangle.yueding.feature.mine.presenter;

import android.text.TextUtils;

import com.fenxiangle.yueding.entity.bo.FoucsBo;
import com.fenxiangle.yueding.entity.bo.LoginPram;
import com.fenxiangle.yueding.entity.bo.UserCenterBo;
import com.fenxiangle.yueding.feature.login.contract.LoginContract;
import com.fenxiangle.yueding.feature.login.dependencies.login.DaggerLoginPresenterComponent;
import com.fenxiangle.yueding.feature.mine.contract.MineContract;
import com.fenxiangle.yueding.feature.mine.dependencies.mine.DaggerMinePresenterComponent;
import com.suozhang.framework.entity.bo.UserInfoBo;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.utils.T;
import com.suozhang.framework.utils.ValidatorUtil;
import com.suozhang.framework.utils.logger.Logger;

import org.json.JSONObject;

import java.io.File;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * LIJUWEN
 *
 * @email yiyayiyayaoljw@gmail.com
 * @date 2017/4/11 9:31
 */
public class MinePresenter implements MineContract.Presenter {

    private MineContract.View mView;


    @Inject

    MineContract.Model mModel;


    public MinePresenter(MineContract.View mView) {
        this.mView = mView;
        DaggerMinePresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }

    @Override
    public void uploadUserHead(String userHead) {
        if (TextUtils.isEmpty(userHead)) {
            mView.showError("请选择头像！");
            return;
        }
        mModel.uploadUserHead(userHead)
                .compose(mView.bindToLife())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {
//                        mView.showLoading(d);
                    }

                    @Override
                    public void onNext(String s) {
//                        mView.dismissLoading();
                        mView.showUploadHeadSuccess(s);
                    }

                    @Override
                    public void onError(Throwable e) {
//                        mView.dismissLoading();
                        mView.showError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
//                        mView.dismissLoading();
                    }
                });
    }



    @Override
    public void getUserData() {
        mModel.getUserData()
                .compose(mView.bindToLife())
                .subscribe(new Observer<UserCenterBo>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mView.showLoading(d);
                    }

                    @Override
                    public void onNext(UserCenterBo s) {
                        mView.dismissLoading();
                        mView.showUserDataSuccess(s);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.dismissLoading();
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
                    }
                });
    }

    @Override
    public void getOtherUserData(String userId) {
        mModel.getOtherUserData(new FoucsBo(userId))
                .compose(mView.bindToLife())
                .subscribe(new Observer<UserCenterBo>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mView.showLoading(d);
                    }

                    @Override
                    public void onNext(UserCenterBo s) {
                        mView.dismissLoading();
                        mView.showUserDataSuccess(s);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.dismissLoading();
                        mView.showError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
                    }
                });
    }

    @Override
    public void upload_user_video(File files, Map<String,String> stringStringMap) {
        mModel.upload_user_video(files,stringStringMap).compose(mView.<String>bindToLife())
                .subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
//                mView.showLoading(d);
            }

            @Override
            public void onNext(String s) {
//                mView.dismissLoading();
                mView.showUploadHeadSuccess(s);

            }

            @Override
            public void onError(Throwable e) {
//                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
//                mView.dismissLoading();
            }
        });
    }


    @Override
    public void attentionFollow(String attentionUserUid) {
        mModel.attentionFollow(new FoucsBo(attentionUserUid))
                .compose(mView.bindToLife())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mView.showLoading(d);
                    }

                    @Override
                    public void onNext(String s ) {
                        mView.dismissLoading();
                        mView.showFollowSuccess();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.dismissLoading();
                        mView.showError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
                    }
                });
    }

    @Override
    public void attentionUnFollow(String attentionUserUid) {
        mModel.attentionUnFollow(new FoucsBo(attentionUserUid))
                .compose(mView.bindToLife())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mView.showLoading(d);
                    }

                    @Override
                    public void onNext(String s ) {
                        mView.dismissLoading();
                        mView.showUnFollowSuccess();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.dismissLoading();
                        mView.showError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
                    }
                });
    }
}
